package com.diyunapp.xilinapp.myindent;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.main.MainActivity;
import com.diyunapp.xilinapp.utils.AbDateUtil;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/*正在申请交易投诉的商品列表页
   在我的fragment查看的页面*/
public class TradeCompDetailActivity extends Activity {

    @Bind(R.id.go_back)
    ImageView goBack;
    @Bind(R.id.complain_time)
    TextView complainTime;
    @Bind(R.id.com_store_name)
    TextView comStoreName;
    @Bind(R.id.com_title)
    TextView comTitle;
    @Bind(R.id.com_info)
    TextView comInfo;
    @Bind(R.id.do_time)
    TextView doTime;
    @Bind(R.id.do_info)
    TextView doInfo;
    @Bind(R.id.lin_do)
    LinearLayout linDo;
    private String complain_id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_trade_comp_detail);
        ButterKnife.bind(this);
        complain_id = getIntent().getStringExtra("complain_id");
        initView();
    }

    private void initView() {
        String url = MainActivity.url + "act=goods&op=complain_detail&member_id=" + MainActivity.myLogin.getMemberid()
                + "&complain_id=" + complain_id;
        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(1000);
        http.send(HttpRequest.HttpMethod.GET, url,
                new RequestCallBack<String>() {
                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
//                        bottom.setVisibility(View.VISIBLE);
                        String resultinfo = responseInfo.result;
                        Log.i("zhangxiaoxidebug", "resultinfo=" + resultinfo);
                        try {
                            JSONObject resultObject = new JSONObject(resultinfo);
                            int result = resultObject.getInt("code");

                            if (result == 200) {

                                JSONObject data = resultObject.optJSONObject("data");
                                long complain_datetime = data.optLong("complain_datetime");
                                String accused_name = data.optString("accused_name");
                                String complain_subject_content = data.optString("complain_subject_content");
                                String complain_content = data.optString("complain_content");
                                long final_handle_datetime = data.optLong("final_handle_datetime");
                                String final_handle_message = data.optString("final_handle_message");
                                complainTime.setText(AbDateUtil.getStringByFormat(complain_datetime * 1000, "yyyy-MM-dd hh:mm:ss"));
                                comStoreName.setText("被投诉店铺：" + accused_name);
                                comTitle.setText("投诉主题：" + complain_subject_content);
                                comInfo.setText("投诉内容：" + complain_content);
                                if (final_handle_datetime != 0) {
                                    doTime.setVisibility(View.VISIBLE);
                                    linDo.setVisibility(View.VISIBLE);
                                    doTime.setText(AbDateUtil.getStringByFormat(final_handle_datetime * 1000, "yyyy-MM-dd hh:mm:ss"));
                                    if (final_handle_message != "") {
                                        doInfo.setText("处理意见：" + final_handle_message);
                                    } else {
                                        doInfo.setText("未处理");
                                    }
                                } else {
                                    doTime.setVisibility(View.GONE);
                                    linDo.setVisibility(View.GONE);
                                }

                            }
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                    }
                });
    }

    @OnClick(R.id.go_back)
    public void onClick() {
        finish();
    }
}
